<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/24/024
 * Time: 20:37
 */

namespace app\admin\model;

use think\facade\Session;
use app\common\model\OssUp;
use app\common\model\TencentVod;

class Upload extends \think\Model
{
    /**
    * 图片上传
    */
    public function _uploadImage($file, $dir = "image"){
        return upload($file, $dir);
    }
    
    /**
    * 图片上传
    */
    public function _uploadFile($file, $dir = "file"){
        return upload_file($file, $dir);
    }
    
    
    /**
    * Oss上传文件
    * @param variable string 上传的变量
    * @param dir string 存储的目录
    */
    public function _uploadOssFile($variable='image', $dir = "other/image"){
       
        if(empty($_FILES)){
            $this->error = '请上传文件';
            return false;
        }
        if($_FILES[$variable]['error'] === 0){
            $file = $_FILES[$variable];
            $type = array_reverse(explode('.', $file['name']));
            $type = $type[0];
            $ob = new OssUp();
            $res = $ob->oss_up($file, $dir, $type);
            if($res){
               return $res;
            }else{
                $this->error = '上传失败';
                return false;
            }
        }else{
            $this->error = '上传失败';
            return false;
        }
    }
    
    /**
    * 腾讯云上传视频
    */
    public function _uploadVedio($variable='image', $dir = "other/image"){
        if(empty($_FILES)){
            $this->error = '请上传文件';
            return false;
        }
        if($_FILES[$variable]['error'] === 0){
            $file = $_FILES[$variable];
            $type = array_reverse(explode('.', $file['name']));
            $type = $type[0];
            $ob = new TencentVod();
            $res = $ob->upload($file['tmp_name']);
            return $res;
        }else{
            $this->error = '上传失败';
            return false;
        }
    }
    
}